package org.balthie.demo.opensource.org.codehaus.plexus.compiler.util.scan;

import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import org.balthie.demo.opensource.org.codehaus.plexus.compiler.util.scan.mapping.SourceMapping;
import org.balthie.demo.opensource.org.codehaus.plexus.util.DirectoryScanner;

public abstract class AbstractSourceInclusionScanner
{
  private final List<SourceMapping> sourceMappings = new ArrayList();

  public final void addSourceMapping(SourceMapping sourceMapping)
  {
    this.sourceMappings.add(sourceMapping);
  }

  protected final List<SourceMapping> getSourceMappings()
  {
    return Collections.unmodifiableList(this.sourceMappings);
  }

  protected String[] scanForSources(File sourceDir, Set<String> sourceIncludes, Set<String> sourceExcludes)
  {
    DirectoryScanner ds = new DirectoryScanner();
    ds.setFollowSymlinks(true);
    ds.setBasedir(sourceDir);
    String[] includes;
    if (sourceIncludes.isEmpty())
    {
      includes = new String[0];
    }
    else
    {
      includes = (String[])sourceIncludes.toArray(new String[0]);
    }

    ds.setIncludes(includes);
    String[] excludes;
    if (sourceExcludes.isEmpty())
    {
      excludes = new String[0];
    }
    else
    {
      excludes = (String[])sourceExcludes.toArray(new String[0]);
    }

    ds.setExcludes(excludes);
    ds.addDefaultExcludes();

    ds.scan();

    return ds.getIncludedFiles();
  }
}